/**
 * Copyright 2021 Huawei Technologies Co., Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ATL_TESTS_BM_USECASES_H_
#define ATL_TESTS_BM_USECASES_H_

#include "container/small_vector.h"
#include <benchmark/benchmark.h>
#include <vector>
#define BM(n) BENCHMARK(n)

NS_BEGIN
static void NAME(BM_construct)(benchmark::State &state) {
  auto len = state.range(0);
  for (auto _: state) {
    VEC_DEF(sv, int64_t, len);
  }
}
BM(NAME(BM_construct))->Range(1, 256);

static void NAME(BM_CopyConstruct)(benchmark::State &state) {
  auto len = state.range(0);
  VEC_DEF(sv, int64_t, len);
  for (auto _: state) {
    auto sv1(sv);
  }
}
BM(NAME(BM_CopyConstruct))->Range(1, 256);

static void NAME(BM_push_back)(benchmark::State &state) {
  auto len = state.range(0);
  VEC_DEF(sv, int64_t, len);
  for (auto _: state) {
    sv.resize(0);
    for (int64_t i = 0; i < len; ++i) {
      sv.push_back(i);
    }
  }
}
BM(NAME(BM_push_back))->Range(1, 256);

static void NAME(BM_at)(benchmark::State &state) {
  auto len = state.range(0);
  VEC_DEF(sv, int64_t, len);
  for (auto _: state) {
    for (size_t i = 0; i < len; ++i) {
      benchmark::DoNotOptimize(sv.at(i));
    }
  }
}
BM(NAME(BM_at))->Range(1, 256);

static void NAME(BM_Assign)(benchmark::State &state) {
  auto len = state.range(0);
  VEC_DEF(sv, int64_t, len);
  const std::vector<int64_t> vec(len, 100);
  for (auto _: state) {
    sv.resize(0);
    sv.assign(vec.begin(), vec.end());
  }
}
BM(NAME(BM_Assign))->Range(1, 256);

NS_END

#endif //ATL_TESTS_BM_USECASES_H_
